home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts44-07
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Re: Borland C++ 4.5 : delete [] operator - what's going on here?
- Date: Fri, 02 Feb 96 19:11:19 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4etnap$7s1@sam.inforamp.net>
- References: <4espam$ddf@rks1.urz.tu-dresden.de>
- NNTP-Posting-Host: ts44-07.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4espam$ddf@rks1.urz.tu-dresden.de>,
- Hoang Minh Son <hoang@eatns1.et.tu-dresden.de> wrote:
- >HI,
- >I'm using EasyWin (Borland C++ 4.5) to test my matrix library under Windows
- 3.1.
- >Could anybody tell me what's wrong in the following code?
- >
- >template<class T> class TMatrix
- >{
- > public:
- > TMatrix(size_t m = 0, size_t n = 0);
- > ~TMatrix()
- > {
- > delete[] elem;
- > delete[] pcol;
- > }
- > T& operator()(size_t i, size_t j);
- > {
- > return pcol[j][i];
- > }
- >
- > //....
- > private:
- > size_t nrow;
- > size_t ncol;
- > T** pcol; // pointer to columns
- > T* elem; // element array
- >};
- >
- >template<class T>
- >TMatrix<T>::TMatrix(size_e m, size_t n) : nrow(m), ncol(n)
- >{
- > elem = new T[m*n+1]; // a dummy space for efficient use
- > pcol = new T*[n+1]; // of 1-based indexing
- >
- > if (n > 0)
- > {
- > pcol[1] = elem;
- > for (int i=1; i <= n; i++)
- > pcol[i+1] = pcol[i] + m;
- > }
- >}
- >
- >typedef TMatrix<double> Matrix;
- >
- >void test()
- >{
- > Matrix a(4,4);
- > for (int i = 1; i <= 4; i++)
- > for (int j = 1; j <= 4; j++)
- > a(i,j) = i + j;
- >}
- >
-
- The four elements of an array
- int a[4];
- are
- a[0], a[1], a[2], a[3]
-
- In your example you use
- a[1], a[2], a[3], a[4]
- and compensate by adding a cell and column.
-
- This is likely your problem.
- This is very unconventional.
-
- Agrivar
-